package com.daniel.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.daniel.model.VUser;
import com.daniel.util.HibernateUtil;

public class VUserDao {
	
	
	public VUser get_v_Userbak( int userid) {
		VUser vuser = null;
		Transaction trns = null;
		Session session = HibernateUtil.getSessionFactory().openSession();
		try {
			trns = session.beginTransaction();
			String queryString = "select userid,dob from VUser where userid=:id";
			Query query = session.createQuery(queryString);
			query.setInteger("id", userid);
			vuser = (VUser) query.uniqueResult();
		} catch (RuntimeException e) {
			e.printStackTrace();
		} finally {
			session.flush();
			session.close();
		}
		return vuser;
	}	
	
	public Object get_v_User( int userid) {
		Object vuser = null;
		Transaction trns = null;
		Session session = HibernateUtil.getSessionFactory().openSession();
		try {
			trns = session.beginTransaction();
			String queryString = "select dob from VUser where userid=:id";
			Query query = session.createQuery(queryString);
			query.setInteger("id", userid);
			vuser =  query.uniqueResult();
			
			
		} catch (RuntimeException e) {
			e.printStackTrace();
		} finally {
			session.flush();
			session.close();
		}
		return vuser;
	}


	
//	public List<VUser> getAllUsers() {
//		List<VUser> users = new ArrayList<VUser>();
//		Transaction trns = null;
//		Session session = HibernateUtil.getSessionFactory().openSession();
//		try {
//			trns = session.beginTransaction();
//			users = session.createQuery("select userid,dob from VUser").list();
//		} catch (RuntimeException e) {
//			e.printStackTrace();
//		} finally {
//			session.flush();
//			session.close();
//		}
//		return users;
//	}
	
}
